< previous page page_569 next page >

Page 569
Dim sDBLocation As String
sDBLocation = "c:\Program Files\Microsoft Visual Studio\VB98\biblio.mdb"
Set dbTest = OpenDatabase(sDBLocation)
These commands open a Jet database with the default options of read/write data access and shared access. The full syntax of the OpenDatabase method lets you specify whether the database should be opened exclusively (no other users or programs can access it at the same time), whether it should be opened in read-only mode (no updates are allowed), or, if you are connecting to a non-Access database, you can specify the database type.
You might, for example, want to use read-only mode for a lookup database (for example, a zip code database or a state abbreviations database that you include with your application but do not want the users to be able to modify). To open the database as read-only, change the Set statement to the form shown in the following line of code. The first parameter after the database name indicates whether the database is opened for exclusive access; the second parameter indicates whether read-only mode is to be used:
Set OldDb = OldWs.OpenDatabase("C:\ZIPCODE.MDB",False,True)
After you open the database, you have only created a link from your program to the database file itself. You still do not have access to the information in the database. To gain access to the information, you must create and open a Recordset object that links to data stored in one or more of the tables in the database.
Deciding Which Recordset Type to Use
When you create a recordset object to open a recordset in your program, you can access any entire table, specific fields and records from the table, or a combination of records and fields from multiple tables. Three types of recordsets are available in Visual Basic:
Recordset Type
Type of Data Contained
Table
All records in an entire physical table in a database.
Dynaset
Sets of pointers that provide access to fields and records in one or more tables of a database.
Snapshot
Read-only copies of data from one or more tables. They are stored in memory.

note.gif This chapter refers to tables, dynasets, and snapshots, but you should remember that they are all recordsets and can be accessed only by using the Recordset object. Specifically, all mentions of tables, dynasets, and snapshots actually refer to table-type recordsets, dynaset-type recordsets, and snapshot-type recordsets, respectively. Previous versions of Visual Basic supported objects that are now outdated: table objects, dynaset objects, and snapshot objects. square.gif

The following sections describe each type of recordset, point out some of the advantages and disadvantages of each, and demonstrate the commands used to access the recordset.

 
< previous page page_569 next page >